*************************************************************************
*																		*
*				Campaign Panel Book Do-File Chapter 2 -	Figure 4		*
*																		*
**************************************************************************
use "${data}\data2009_2013 participants 7 waves.dta", clear


estimates clear
foreach year in a b {
foreach partei in cdu spd fdp gru link {
foreach welle of numlist 2/7 {
 logit `year'_gespr`partei'`welle' b808.`year'_pidfull1  `year'_polint2 ///
	if !missing(`year'_gespr`partei'2, `year'_gespr`partei'3, ///
				`year'_gespr`partei'4, `year'_gespr`partei'5, ///
				`year'_gespr`partei'6, `year'_gespr`partei'7) & ///
				`year'_pidfull1~=801 [pw=`year'_weight]
				
margins `year'_pidfull1, post atmeans

estimates store `year'_point`partei'`welle'


capture gen `year'_help`partei'1`welle' = _b[1.`year'_pidfull1] if e(sample)
capture gen `year'_help`partei'4`welle' = _b[4.`year'_pidfull1] if e(sample)
capture gen `year'_help`partei'5`welle' = _b[5.`year'_pidfull1] if e(sample)
capture gen `year'_help`partei'6`welle' = _b[6.`year'_pidfull1] if e(sample)
capture gen `year'_help`partei'7`welle' = _b[7.`year'_pidfull1] if e(sample)
capture gen `year'_help`partei'808`welle' = _b[808.`year'_pidfull1] if e(sample)

}
}
}

//fre a_helplink21		//perfect prediction for CDU/CSU-identifiers Linke-discussant = 0 
gen a_helplink12 =0 


fre a_helpcdu12 
/* spelled out party name indicates party of the dependent variable,
first number indicates the wave and second number indicates the party of 
the independent variable*/





reshape long a_helpcdu1 a_helpcdu4 a_helpcdu5 a_helpcdu6 a_helpcdu7 a_helpcdu808 ///
	a_helpspd1 a_helpspd4 a_helpspd5 a_helpspd6 a_helpspd7 a_helpspd808 ///
	b_helpcdu1 b_helpcdu4 b_helpcdu5 b_helpcdu6 b_helpcdu7 b_helpcdu808 ///
	b_helpspd1 b_helpspd4 b_helpspd5 b_helpspd6 b_helpspd7 b_helpspd808, i(lfdn) j(welle)


fre ?_helpcdu1	


sum a_helpspd5 if welle == 2
sum a_helpcdu4 if welle == 2

sort welle

fre welle


graph set window fontface "Times New Roman"


graph twoway ///
	(connected b_helpcdu1 welle) ///
	(connected b_helpcdu4 welle) ///
	(connected b_helpcdu5 welle) ///
	(connected b_helpcdu6 welle) ///
	(connected b_helpcdu7 welle) ///
	(connected b_helpcdu808 welle), ///
	legend(label(1 "CDU/CSU") label(2 "SPD") label(3 "FDP") label(4 "Greens") ///
	label(5 "Left Party") label(6 "Independent") cols(3) region(lwidth(none))) ///
	xtitle("Wave", alignment(bottom) margin(medium)) xlabel(2(1)7) ///
	ytitle("Probability", margin(medium)) ylabel(,angle(horizontal))  ///
	scheme(s1mono) name(prob_cdu13, replace) 
graph export "${path}\Reproducible Do-Files\Chapter 2\Figuresprobability_selective talk 2013 CDU.png", width(2200) height(1800) replace

graph twoway ///
	(connected b_helpspd1 welle) ///
	(connected b_helpspd4 welle) ///
	(connected b_helpspd5 welle) ///
	(connected b_helpspd6 welle) ///
	(connected b_helpspd7 welle) ///
	(connected b_helpspd808 welle), ///
		legend(label(1 "CDU/CSU") label(2 "SPD") label(3 "FDP") ///
		label(4 "Greens") ///
		label(5 "The Left") label(6 "Independent") cols(3) region(lwidth(none))) ///
		xtitle("Wave", alignment(bottom) margin(medium)) xlabel(2(1)7) ///
		ytitle("Probability", margin(medium)) ylabel(,angle(horizontal))  ///
		scheme(s1mono) name(prob_spd13, replace) 
graph export "${path}\Reproducible Do-Files\Chapter 2\Figuresprobability_selective talk 2013 SPD.png", width(2200) height(1800) replace
		